package com.pucong.gitee.database.backup.configuration.quartz;

import com.pucong.gitee.database.backup.business.service.util.pool.FtpConnectionManager;
import com.pucong.gitee.database.backup.business.database.util.jdbcPool.JdbcConnectionManager;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * 应用启动监听
 *
 * @author pucong
 */
@Configuration
public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private MyQuartzScheduler myQuartzScheduler;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            myQuartzScheduler.startJob();
            // 开始线程,维护连接池
            JdbcConnectionManager thread = new JdbcConnectionManager();
            thread.start();
            FtpConnectionManager thread2 = new FtpConnectionManager();
            thread2.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

}
